import sdk from '../core/index';
import { DataEquip } from "../shared/face/index";
import { quality } from "../shared/face/enums";
import { analysisIntent } from "../core/tool/baseScene";
import { mathType } from "../core/tool/face";
import common from "../core/tool/common";
import component, { ComType } from "../core/tool/component";
import { Icard } from "../core/tool/Icard";
import bag_component from "./bag_component";
// 技能商店组件
export default class shopEquip_component extends component {
    sell_data!:DataEquip;
    refCont:number = 0;
    refTime:number = 0;
    sellPrice:number = 0;
    constructor() {
        super();
    }
    init() {
    }
    client_main(data:analysisIntent){
        // if(!this.sell_data){
        //     this.reloadEquip();
        // }
        // if(common.countDown(this.refTime) <= 0){
        //     this.refCont = 0;
        //     this.reloadEquip();
        // }
        // let card = new Icard();
        // card.title(`装备商店`);
        // card.l(`当前出售:${quality[this.sell_data?.quality]}${this.sell_data?.name}`);
        // card.l(`购买价格:${this.sellPrice}💰`);
        // card.l(`主动刷新:${this.refCont * 100}💰`);
        // card.l(`自动刷新:${common.countDown(this.refTime)}秒`);
        // card.l(`↓ ↓ ↓ 装备预览 ↓ ↓ ↓`);
        // this.registerShopEquipButtonIntents(card);
        // this.client_text(card.getText());
        
        // sdk.prop.client_equip(this.sell_data, sdk.tool.card.create2())
    }
    client_buy(data:analysisIntent){
        let com_bag = this.getComponent(ComType.背包) as bag_component;
        let jude =  com_bag.goldBuy(this.sellPrice)
        if(jude){
            let item = sdk.prop.cover_equipToItem(this.sell_data);
            com_bag.addItem(item);
            this.client_text(`购买成功!`);
        }else{
            this.client_text(`购买失败!`);
        }
    }
    /**
     * 主动刷新技能
     * @param data 
     */
    client_refresh(data:analysisIntent){
        let com_bag = this.getComponent(ComType.背包) as bag_component;
        let jude =  com_bag.goldBuy(this.refCont * 100);
        if(jude){
            this.client_text(`刷新成功!`);
            this.refCont++;
            this.reloadEquip();
            this.client_main(data);
        }else{
            this.client_text(`刷新失败!`);
        }
    }
    private reloadEquip(){
        // let com_post = this.getComponent(ComType.位置) as pos_component;
        // let _tableName = `${configKey.装备_资源表}_${com_post.sceneName}`;
        // let _cfg = config.get(_tableName) as Map<string,any>;
        // const equips = Array.from(_cfg.values())
        // .filter(item => !item.notBuy);


        // const randomSkill = equips[Math.floor(Math.random() * equips.length)];
        // let temp = PropManage.createEquip(randomSkill) as DataEquip;
        // this.sell_data = temp;
        // this.refTime = Date.now() + 5 * 60 * 1000;
        // let basePrice = (temp.quality + 1) * 100;
        // this.sellPrice = sdk.tool.common.random(basePrice,basePrice * 2);
    }
    
    // 注册装备商店按钮意图的通用方法
    private registerShopEquipButtonIntents(card: Icard): void {
        const buttonConfigs = [
            { text: '购买', action: 'client_buy', mathType: mathType.完全匹配, isHideMath: false },
            { text: '刷新', action: 'client_refresh', mathType: mathType.完全匹配, isHideMath: false }
        ];
        
        this.registerButtonIntents(card, buttonConfigs);
    }
}

